package com.gh.controller;

import com.gh.model.hosp.Hospital;
import com.gh.result.Result;
import com.gh.service.HospitalService;
import com.gh.vo.hosp.DepartmentVo;
import com.gh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author Eric
 * @Date 2021/6/9 23:46
 * @Version 1.0
 */
@RestController
@RequestMapping("admin/hosp/hospital")
//@CrossOrigin
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;
    @PostMapping("list/{page}/{limit}")
    public Result listHosp(@PathVariable Integer page,
                           @PathVariable Integer limit,
                           @RequestBody(required = false) HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> pageModel = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        List<Hospital> content = pageModel.getContent();
        long totalElements = pageModel.getTotalElements();

        return Result.ok(pageModel);
    }
    /**
     * 更新医院上线状态
     */
    @PutMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable String id,
                               @PathVariable Integer status){
        hospitalService.updateStatus(id,status);
        return Result.ok();
    }
    /**
     * 查询医院详情
     */
    @GetMapping("findHospitalById/{id}")
    public Result findHospitalById(@PathVariable String id){
        Map<String,Object> map = hospitalService.findHospitalById(id);
        return Result.ok(map);
    }
    /**
     * 根据医院编号查询科室信息（大科室下有小科室）
     */
    @ApiOperation(value = "查询医院科室列表")
    @GetMapping("getDeptList/{hoscode}")
    public Result findDeptList(@PathVariable String hoscode){
        List<DepartmentVo> departmentVos=hospitalService.findDeptList(hoscode);
        return Result.ok(departmentVos);
    }
}
